<template>
    <div class="widget">
        <li class="widget-item">
            <p class="widget-title">标题</p>
            <el-input type="text" class="val" size="mini" v-model="formData.title" />
        </li>
        <li class="widget-item">
            <p class="widget-title">作战单元</p>
            <el-select v-model="formData.unit" class="widget-select" size="mini" :popper-append-to-body="false"
                popper-class="select-popper" placeholder="请选择">
                <el-option v-for="item in units" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
            </el-select>
        </li>
        <li class="widget-item">
            <p class="widget-title">数量</p>
            <el-input-number class="val" size="mini" v-model="formData.unit_num" />
        </li>

</div>
</template>
<script>

export default {
    props: {},
    data() {
        return {
            content: {
            },
            formData: {
                unit_num: 1
            },
            units: [],
            defaultValue: '',
        };
    },
    methods: {
        commitData() {
            this.defaultValue = JSON.stringify(this.formData)
            this.content.defaultValue = this.defaultValue
            this.$EventBus.$emit('defaultValue', this.content)
        },
        getUnits() {
            this.units = [
                { label: "飞行编队1", value: "formation1" },
                { label: "飞行编队2", value: "formation2" },
                { label: "无", value: "" },
            ]
        },
        actionChange(){
            console.log("actionchagne")
            if(this.formData.action=='attack'){
                this.displayTarget = true
                this.displayAddress = false
            }
            if(this.formData.action=='patrol'){
                this.displayTarget = false
                this.displayAddress = true
            }
            if(this.formData.action=='setting'){
                this.displayTarget = false
                this.displayAddress = false
            }
        }
    },
    mounted() {
        console.log("this.context", this.content)
        this.defaultValue = this.content.defaultValue
        if (this.defaultValue) {
            this.formData = JSON.parse(this.defaultValue)
        }
        this.getUnits()

    },
    beforeDestroy(){
        this.commitData()
    }
};
</script>

<style lang="less" scoped>
.val {
    width: 180px;
}
</style>
